
<?php
		
	$var = @$_GET['id'] ;
	
	//connect to your database ** EDIT REQUIRED HERE **
	include('config.php');
	
	// Build SQL Query  
	//$query = "SELECT * FROM tbartifacts WHERE Title LIKE \"%$trimmed%\" OR Text LIKE \"%$trimmed%\" " ; 
	
	$query = "SELECT tbartifacts.Title, tbartifacts.Text, tbartifacts_type.Name, 
	          tbartifacts.File, tbusers.Id AS AuthorId, tbusers.Name AS Author
			  FROM tbartifacts, tbartifacts_type, tbusers 
			  WHERE tbartifacts.Id = \"$var\"  
			  AND tbartifacts.Type = tbartifacts_type.Id AND tbartifacts.Author = tbusers.Id";
	
	
	
	  //ORDER BY Name"; // EDIT HERE and specify your table and field names for the SQL query
	
	/*$query = sprintf("SELECT * FROM tbartifacts WHERE Title LIKE '%s' ORDER BY Id ",    
		mysql_real_escape_string($trimmed));*/
	
	mysql_query("set names utf8");
	 
	$numresults = mysql_query($query);
	 
	if (!$numresults) 
	{
		die('Invalid query: ' . mysql_error());
	}
					
		 
	$row = mysql_fetch_assoc($numresults);

	// Get the File's name
	$file = $row["File"];	
	
	echo(" <p> TITLE = " . $row["Title"] . " </p>");
    echo("<br/>");
	echo(" <p> TYPE = " . $row["Name"] . " </p>");
    echo("<br/>");
	echo(" <p> AUTHOR = " . $row["Author"] . " </p>");
    echo("<br/>");
	echo(" <p> DESCRIPTION = " . $row["Text"] . " </p>");	
	echo("<br/><br/>");
	echo(" <p> <img src='storage/".$var."/images/image.jpg' width='300' height='300' /> </p> ");
	echo(" <br/><br/>");
	echo(" <p> <a href='storage/".$var."/files/".$file."'> <img src='img/btnDownload.png'> </a>  </p>");
	
     
     
	if( isset( $_SESSION['userid'] ) && ($row["AuthorId"] == $_SESSION['userid'])  )
	{ 
		echo(" <br/>");
		echo(" <p> <a href='editarmodelo.php?id=" . $var . "'>EDITAR</a> </p>");
		echo(" <br/>");
		echo(" <p> <a href='apagarmodelo.php?id=" . $var . "'>APAGAR</a> </p>");		
	} 				
		

		
	
	// If we have no results
	
	if ($numresults == 0)
	{
		//echo "<h4>Results</h4>";
		//echo "<p>Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results</p>";
	}//if
	
	  
?>